﻿#include "render/sdl_window.h"
#include "klbmem/klb_mem.h"


/// @brief 创建一个窗口
sdl_window_t* sdl_window_create(int w, int h, const char* p_title)
{
    sdl_window_t* p_wnd = KLB_MALLOCZ(sdl_window_t, 1, 0);

    SDL_CreateWindowAndRenderer(w, h, SDL_WINDOW_SHOWN, &p_wnd->p_window, &p_wnd->p_render);
    assert(NULL != p_wnd->p_window);
    assert(NULL != p_wnd->p_render);

    SDL_SetWindowTitle(p_wnd->p_window, p_title);

    return p_wnd;
}

/// @brief 销毁窗口
void sdl_window_destroy(sdl_window_t* p_wnd)
{
    KLB_FREE_BY(p_wnd->p_render, SDL_DestroyRenderer);
    KLB_FREE_BY(p_wnd->p_window, SDL_DestroyWindow);

    KLB_FREE(p_wnd);
}

void sdl_window_present(sdl_window_t* p_wnd)
{
    SDL_RenderPresent(p_wnd->p_render);
}
